package com.xsz.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.*;

import com.xsz.entity.OrderMaster;

@Api(value = "测试控制类")
@RestController
public class TestController {
	
			//路径传值
			//http://localhost:9001/springboot1/t1/aaaa
			@ApiOperation(value = "路径传值", notes = "p1是值")
			@ApiImplicitParam(name = "p1", value = "测试的参数", required = true, dataType = "String", paramType = "path")
			@GetMapping("t1/{p1}")
			public Map t1(@PathVariable("p1") String paramter1){
				Map map=new HashMap();
				map.put("rs",paramter1);
				return  map;
			}
			//? 传值
			//http://localhost:9001/springboot1/t2?p1=aaaa
			@ApiOperation(value = "? 传值", notes = "? 传值")
			//@ApiImplicitParam(name = "p1", value = "测试的参数", required = true, dataType = "String", paramType = "path")
			@GetMapping("t2")
			public Map t2(@RequestParam("p1") String paramter1)
			{
				System.out.println(paramter1);
				Map map=new HashMap();
				map.put("rs",paramter1);
				return  map;
			}

			//Body参数
		   //application/json
			@ApiOperation(value = "JSON传值", notes = "参数必须是JSON格式")
			@ApiImplicitParam(name = "master", value = "订单对象", required = true, dataType = "OrderMaster")
			@PostMapping("t3")
			public Map t3(@RequestBody OrderMaster master){

				Map map=new HashMap();
				map.put("rs",master.getUserName());
				return  map;
			}
//			无注解（form提交）
			//form-data
			@ApiOperation(value = "form提交", notes = "form提交")
			@PostMapping("t4")
			public Map t4(OrderMaster master){

				Map map=new HashMap();
				map.put("rs",master.getUserName());
				return  map;
			}

//			请求头参数以及Cookie
			@GetMapping("t5")
			public Map t5(@RequestHeader(name ="myHeader") String myHeader,
							 @CookieValue(name = "myCookie") String myCookie){
				System.out.println("myHeader=" + myHeader);
				System.out.println("myCookie=" + myCookie);
				Map map=new HashMap();
				map.put("rs",myHeader);
				return  map;
			}

//			表单的参数写在Controller相应的方法的形参中
//			适用于get方式提交，不适用于post方式提交。
			@GetMapping("t6")
			public Map t6(String name,String pwd){

				Map map=new HashMap();
				map.put("rs",name);
				return  map;
			}


}
